<?php
declare (strict_types = 1);

namespace app\command;
use think\App;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use app\controller\clean\Stream;
use app\model\HandleProject;
use app\model\HandleFileRow;
use app\model\HandleProjectTask;

class CheckTaskCommand extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('checkTask')
            ->setDescription('这是一个任务完成度检查的定时器');
    }

    protected function execute(Input $input, Output $output)
    {
        // 指令输出
        // $output->writeln('checkTask Hanlibao');
        $app = new App();
        $app->initialize();
        $projectInfo = HandleProject::ins()->where([['clean_status','>',0]])->order('id','desc')->find();
        $streamObj = new Stream($app);
        if($projectInfo['clean_status']===1){ // 如果项目的清洗状态是执行中，定时读取执行进度
            $streamObj->readRenameCallback($projectInfo); // 读取文件改名callback
        }
        
        // 查询检查表里有没有没完成的任务
        $incomplete_number = HandleFileRow::ins()->where('state',0)->count();
        if($incomplete_number > 0 ){
            $streamObj->readCheckFileCallback(false);
        }else{
            HandleProjectTask::ins()->where('state',1)->update(['state'=>3]);
        }
        
    }
}


// */5 * * * * cd /var/www/html && php think checkTask >> /tmp/tp8_cron.log 2>&1